package xiaoka.ecarx.com.cn.upnpserverdemo;

import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;

import java.io.IOException;

/**
 * Created by Chong Zhao on 2016/10/30.
 */
public class PlayerService extends Service {
    private static final String TAG = "PlayerService";
    private IBinder mIBinder;
    private MediaPlayer mp;
    public PlayerService() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        return  mIBinder;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Toast.makeText(this, "点烟器的播放器服务正在初始化", Toast.LENGTH_SHORT).show();
        mp = new MediaPlayer();
        try {
            mp.reset();
            mp.setDataSource("http://mp3.haoduoge.com/s/2016-09-12/1473684651.mp3");

            mp.prepare();
            mp.start();
            mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                @Override
                public void onCompletion(MediaPlayer mp) {
                    mp.start();
                    Log.i(TAG, "onCreate:http://mp3.haoduoge.com/s/2016-09-12/1473684651.mp3 ");
                }
            });
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
